package de.fhkl.gatav.ut.framedancer_2;

import de.fhkl.gatav.ut.framedancer_2.R;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class FrameDancer_2_Activity extends Activity {
	private ImageView animView;
	private Boolean isRunning; 
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
		animView = (ImageView) findViewById(R.id.danceView);
		final AnimationDrawable frameAnimation = (AnimationDrawable) animView.getDrawable();
		isRunning = true;

		animView.post( 
			new Runnable() {
				public void run() { 
					frameAnimation.start();
				}
			}
		);
    }
    
    public void onClick_dance(View view) {
		AnimationDrawable frameAnimation;
		frameAnimation = (AnimationDrawable)animView.getDrawable();
		final Button danceToggle = (Button) findViewById(R.id.danceToggle);
		
		if (isRunning) {
			frameAnimation.stop();
			isRunning = false;
			danceToggle.setText(R.string.dance_text);
		} else {
			frameAnimation.start();
			isRunning = true;
			danceToggle.setText(R.string.stop_text);
		}
    }
}